package com.example.a22310.myapplication.ViewModel.Order;

import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.TrainOrder;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.OrderModel;
import com.example.a22310.myapplication.databinding.ActivityOrderBinding;

import java.util.List;

public class ActivityOrderViewModel  implements ActivityLisenter<TrainOrder> {

    private ActivityOrderBinding binding;
    private AppCompatActivity activity;
    private int userid;


    public ActivityOrderViewModel(AppCompatActivity activity, ActivityOrderBinding binding, int userid){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        binding.setTrain(this);
        OrderModel orderModel=new OrderModel();
        orderModel.activityOrderlist(ActivityOrderViewModel.this,userid);

    }



    @Override
    public void onSuccess(TrainOrder order) {
        if(order.getCode()!=404){
            List<TrainOrder.OrderlistBean> orderlistBean =  order.getOrderlist();
            binding.recyclerViewActivity.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_train_order,
                    orderlistBean, BR.order);
            binding.recyclerViewActivity.setAdapter(adapter);

        }

    }

    @Override
    public void onFailure() {
    }
}
